package com.bluesky.drcp.persistence.dao.hibernate;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.bluesky.drcp.business.Role;
import com.bluesky.drcp.persistence.dao.RoleDao;

public class RoleDaoImpl extends HibernateDaoSupport implements RoleDao {

	public boolean isAuthorized(String id, String entryId) {
		Object[] p = new Object[] { id, entryId };
		List list = getHibernateTemplate().find(
				"from FunctionAuthorization where roleId=? and entryId=?", p);

		return (!list.isEmpty());

	}

	public void delete(String id) {
		Role role = (Role)getHibernateTemplate().get(Role.class, id);
		getHibernateTemplate().delete(role);
	}

	public Role get(String id) {
		return (Role)getHibernateTemplate().get(Role.class, id);
	}

	public List getAll() {
		return getHibernateTemplate().find("from Role");		
	}

	public String save(Role role) {
		getHibernateTemplate().save(role);	
		return role.getId();
	}

	public void update(Role role) {
		getHibernateTemplate().update(role);		
	}
	
}
